package com.guigu.controller;


import com.guigu.pojo.ProductType;
import com.guigu.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.ProductType;
import com.guigu.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2025-03-12
 */
@CrossOrigin
@RestController
@RequestMapping("/product-type")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    @PostMapping("/getProductType")
    @ResponseBody
    public Page<ProductType> getProductType(@RequestBody HashMap<String,Object> map){
        Page<ProductType> productType = productTypeService.getProductType(map);
        System.out.println(productType);

        return productType;
    }

    @GetMapping("/getAllGoodsType")
    @ResponseBody
    public List<ProductType> getAllGoodsType(){
        List<ProductType> productType = productTypeService.list();
        return productType;
    }

    @GetMapping("/getProductTypeFirstLevel")
    @ResponseBody
    public List<ProductType> getProductTypeFirstLevel(){
        List<ProductType> productTypeFirstLevel = productTypeService.getProductTypeFirstLevel();
        return productTypeFirstLevel;
    }

    @GetMapping("/getProductTypeSecondLevel")
    @ResponseBody
    public List<ProductType> getProductTypeSecondLevel(){
        List<ProductType> productType = productTypeService.getProductTypeSecondLevel();
        return productType;
    }

    @GetMapping("/getAllProductType")
    @ResponseBody
    public List<ProductType> getAllProductType(Integer level) {
        if (level == null) {
            return productTypeService.getAllProductType();
        }else{
            return productTypeService.getAllProductTypeByLevel(level);
        }
    }

//    @GetMapping("/getAllParentProductType")
//    @ResponseBody
//    public List<ProductType> getAllParentProductType() {
//        return productTypeService.getAllProductTypeByLevel(1);
//    }

}

